home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group01b.txt / 000134_icon-group-sender_Tue Aug 7 16:45:42 2001.msg < prev    next >
Internet Message Format  |  2002-01-03  |  2KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id f77NhlE26494
  4.     for icon-group-addresses; Tue, 7 Aug 2001 16:43:47 -0700 (MST)
  5. Message-Id: <200108072343.f77NhlE26494@baskerville.CS.Arizona.EDU>
  6. Date: Tue, 07 Aug 2001 15:20:43 -0700
  7. From: Steve Wampler <swampler@noao.edu>
  8. X-Accept-Language: en
  9. To: icon-group@cs.arizona.edu
  10. Subject: Re: Sorting
  11. Errors-To: icon-group-errors@cs.arizona.edu
  12. Status: RO
  13. Content-Length: 1688
  14.  
  15. Anders Holtsberg wrote:
  16. > What is the simplest way to sort a list of records according to
  17. > one of the fields? It seems hat this is not a one liner, or is
  18. > it? My quick hack is this:
  19. > procedure sortbyfield(thelist, i)
  20. >    t := table(&null)
  21. >    every e := !thelist do t[e[i]] := e;
  22. >    s := sort(t, 1)
  23. >    w := []
  24. >    every put(w, (!s)[2])
  25. >    return w
  26. > end
  27.  
  28. Seems like a reasonable approach to me.  Of course, it does
  29. assume that all the elements in the list are subscriptable
  30. [and imagine what happens if there are some strings stuck in there!].
  31. Of course, since you (as the programmer) know the list contains
  32. only records it should work quite nicely.
  33.  
  34. > For tables one can give a second argument to the sort procedure,
  35. > but for lists the second argument is simply ignored.
  36. > One simple for future enhancement to Icon is to use the above
  37. > semantics for a two argument call to sort, where the first
  38. > argument is either a list of records or a list of lists. Even
  39. > better is to also accept a string as second argument for the
  40. > case that the first argument is a list of records. Is this
  41. > sensible?
  42.  
  43. I think it's an interesting idea, but probably needs some more
  44. work on the details.  Since there is no concept of a homogeneous
  45. list in Icon, there need to be clearly defined rules on how to
  46. sort elements that don't contain anything matching the sort
  47. field index - generating a runtime error as the above code
  48. does is probably not acceptable in the general case.
  49.  
  50. If you're going to add this to sort for sorting lists, it might be
  51. good to also add it to sort for sorting tables as well!
  52.  
  53. --
  54. Steve Wampler-  SOLIS Project, National Solar Observatory
  55. swampler@noao.edu
  56.